//
//  HealthComInfoVC.m
//  Ginix
//
//  Created by fzq on 2025/2/23.
//

#import "HealthComInfoVC.h"
#import "HomeComInfoCell.h"
#import "HomeComtypeCell.h"
#import "HomePulseCell.h"
#import "HomeTongueCell.h"
#import "HomeConstiCell.h"
#import "HomeComDataCell.h"
#import "HomeComTriggerView.h"
#import "HomeComNurseCell.h"
#import "HomeAllCheckVC.h"
@interface HealthComInfoVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView * listtView;
@property (nonatomic,strong) HomeAllCheckModel * infoModel;

@end

@implementation HealthComInfoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setSubViewLayout];
    [self requestData];
}

-(void)setSubViewLayout{
    
    self.title = @"报告详情";
    [self.view addSubview:self.listtView];
    [_listtView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(NavHeight +20 * FMScaleX, 0, 20 * FMScaleX, 0));
    }];
    [(BaseNavController *)[UIViewController findNavigationController]addFullScreenPopBlackListItem:self];

}

-(void)requestData{
    @WeakObj(self)
    [SPNetworkingIns POST:PORT(@"bh-center/api/invite/getUserHealthTestAndId") params:@{@"id":self.ID} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject, NSInteger code) {
        @StrongObj(self)
        self.infoModel = [HomeAllCheckModel yy_modelWithDictionary:responseObject[@"data"]];
        [self.listtView reloadData];
    } fail:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
    }];
}

-(void)backBtnClick{
    
    [self checkAndPopWithTargetClass:HomeAllCheckVC.class];
}

- (void)checkAndPopWithTargetClass:(Class)targetClass {
    // 获取导航控制器的视图控制器栈
    NSArray<UIViewController *> *viewControllers = self.navigationController.viewControllers;

    // 判断特定页面是否存在
    BOOL targetExists = NO;
    for (UIViewController *vc in viewControllers) {
        if ([vc isKindOfClass:targetClass]) {
            targetExists = YES;
            break;
        }
    }
    // 根据判断结果执行 pop 操作
    if (targetExists) {
        // 若存在指定页面，pop 到根视图控制器
        [self.navigationController popToRootViewControllerAnimated:YES];
    } else {
        // 若不存在，pop 到上级视图控制器
        [self.navigationController popViewControllerAnimated:YES];
    }
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 7;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    switch (indexPath.row) {
        case 0:
            return  60 * FMScaleX;
            break;
        case 1:
            return  180 * FMScaleX;
            break;
        case 2:
            return  240 * FMScaleX;
            break;
        case 3:
            return  480 * FMScaleX;
            break;
        case 4:
            return  240 * FMScaleX;
            break;
        case 5:
            return  520 * FMScaleX;
            break;
        case 6:
            return  200 * FMScaleX;
            break;
        case 7:
            return  90 * FMScaleX;
            break;
        default:
            return 0;
            break;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        HomeComInfoCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeComInfoCell"];
        [cell setInfoModel:self.infoModel type:1];
        return cell;
    }
    if(indexPath.row == 1){
        HomeComtypeCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeComtypeCell"];
        [cell setInfoModel:self.infoModel];
        return cell;
    }
    if (indexPath.row == 2) {
        HomePulseCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomePulseCell"];
        [cell setInfoModel:self.infoModel.result.diagnosis];
        return cell;
    }
    if (indexPath.row == 3) {
        HomeTongueCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeTongueCell"];
        [cell setInfoModel:self.infoModel.result.diagnosis];
        return cell;
    }
    if (indexPath.row == 4) {
        HomeComDataCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeComDataCell"];
        [cell setInfoModel:self.infoModel.result.diagnosis];
        return cell;
    }
    if (indexPath.row == 5) {
        HomeComTriggerView * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeComTriggerView"];
        [cell setInfoModel:self.infoModel.result.diagnosis];
        return cell;
    }    
    HomeComNurseCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeComNurseCell"];
    [cell setInfoModel:self.infoModel.result.diagnosis];
    return cell;
}


-(UITableView *)listtView{
    
    if (!_listtView) {
        _listtView = [[UITableView alloc]init];
        _listtView.delegate = self;
        _listtView.dataSource = self;
        _listtView.showsVerticalScrollIndicator = NO;
        _listtView.showsHorizontalScrollIndicator = NO;
        _listtView.backgroundColor = UIColor.clearColor;
        _listtView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _listtView.bounces = NO;
        [_listtView registerClass:[HomeComInfoCell class] forCellReuseIdentifier:@"HomeComInfoCell"];
        [_listtView registerClass:[HomeComtypeCell class] forCellReuseIdentifier:@"HomeComtypeCell"];
        [_listtView registerClass:[HomePulseCell class] forCellReuseIdentifier:@"HomePulseCell"];
        [_listtView registerClass:[HomeTongueCell class] forCellReuseIdentifier:@"HomeTongueCell"];
        [_listtView registerClass:[HomeConstiCell class] forCellReuseIdentifier:@"HomeConstiCell"];
        [_listtView registerClass:[HomeComDataCell class] forCellReuseIdentifier:@"HomeComDataCell"];
        [_listtView registerClass:[HomeComTriggerView class] forCellReuseIdentifier:@"HomeComTriggerView"];
        [_listtView registerClass:[HomeComNurseCell class] forCellReuseIdentifier:@"HomeComNurseCell"];

    }
    return _listtView;
}

@end
